package com.feiyuan.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.feiyuan.modules.sys.entity.RoleEntity;
import com.feiyuan.modules.sys.service.RoleService;
import com.feiyuan.common.utils.PageUtils;
import com.feiyuan.common.utils.ResponseUtils;



/**
 * 
 *
 * @author Xupf
 * @email xupengfei131276@126.com
 * @date 2024-03-01 14:51:34
 */
@RestController
@RequestMapping("/admin/sys/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("sys:role:list")
    public ResponseUtils list(@RequestParam Map<String, Object> params){
        PageUtils page = roleService.queryPage(params);

        return ResponseUtils.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("sys:role:info")
    public ResponseUtils info(@PathVariable("id") Long id){
		RoleEntity role = roleService.getByIdInfo(id);

        return ResponseUtils.ok().put("role", role);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("sys:role:save")
    public ResponseUtils save(@RequestBody RoleEntity role){
		roleService.saveRole(role);

        return ResponseUtils.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("sys:role:update")
    public ResponseUtils update(@RequestBody RoleEntity role){
        role.setUpdateTime(new Date());
		roleService.updateByIdRole(role);

        return ResponseUtils.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("sys:role:delete")
    public ResponseUtils delete(@RequestBody Long[] ids){
        roleService.removeByIdsRole(Arrays.asList(ids));

        return ResponseUtils.ok();
    }

}
